var app = getApp(), siteinfo = require("../../../siteinfo.js");

Page({
    data: {
        icon: !0
    },
    onLoad: function(e) {
        var t = this;
        t.setData({
            id: e.id
        }), wx.hideShareMenu(), app.util.request({
            url: "entry/wxapp/url",
            cachetime: "0",
            success: function(e) {
                console.log("这是网址"), console.log(e), t.setData({
                    url: e.data
                });
            }
        }), app.getUserInfo(function(e) {
            t.setData({
                userInfo: e
            });
        });
    },
    choose1: function(e) {
        var a = this, o = siteinfo.siteroot;
        wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(e) {
                var t = e.tempFilePaths[0];
                wx.uploadFile({
                    url: o + "?i=" + a.data.userInfo.uniacid + "&c=entry&a=wxapp&do=upload&m=zh_gjhdbm",
                    filePath: t,
                    name: "upfile",
                    formData: {},
                    success: function(e) {
                        console.log(e), a.setData({
                            zm_img: e.data
                        });
                    },
                    fail: function(e) {}
                }), a.setData({
                    logo: t
                });
            }
        });
    },
    choose2: function(e) {
        var a = this, o = wx.getStorageSync("siteroot");
        wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(e) {
                var t = e.tempFilePaths[0];
                wx.uploadFile({
                    url: o + "?i=" + a.data.userInfo.uniacid + "&c=entry&a=wxapp&do=upload&m=zh_gjhdbm",
                    filePath: t,
                    name: "upfile",
                    formData: {},
                    success: function(e) {
                        console.log(e), a.setData({
                            fm_img: e.data
                        });
                    },
                    fail: function(e) {}
                }), a.setData({
                    logo: t
                });
            }
        });
    },
    formSubmit: function(e) {
        var t = this;
        console.log(e);
        var a = e.detail.formId, o = e.detail.value.name, n = e.detail.value.code, i = e.detail.value.representative, s = t.data.zm_img, c = t.data.fm_img, u = t.data.icon, l = t.data.id;
        console.log(l);
        var r = "";
        "" == o ? r = "请输入企业名称" : "" == n ? r = "请输入工商执照注册码" : "" == i ? r = "请输入法定代表人姓名" : null == s ? r = "请上传正面照片以便核实" : null == c ? r = "请上传反面照片以便核实" : 0 == u && (r = "请阅读并同意认证须知"), 
        "" != r ? wx.showModal({
            title: "温馨提示",
            content: r
        }) : 0 == l ? app.util.request({
            url: "entry/wxapp/saveattestation",
            cachetime: "0",
            data: {
                user_id: t.data.userInfo.id,
                name: o,
                zj_name: i,
                code: n,
                zm_img: s,
                bm_img: c,
                type: 2
            },
            success: function(e) {
                if (console.log(e), "error" != e.data) {
                    wx.showToast({
                        title: "提交成功"
                    }), setTimeout(function() {
                        wx.navigateBack({
                            delta: 2
                        });
                    }, 1500);
                    var t = wx.getStorageSync("userInfo").openid;
                    app.util.request({
                        url: "entry/wxapp/Message3",
                        cachetime: "0",
                        data: {
                            form_id: a,
                            openid: t,
                            rz_id: e.data
                        },
                        success: function(e) {
                            console.log("发送模板消息"), console.log(e);
                        }
                    });
                } else wx.showModal({
                    title: "",
                    content: "系统出差了，待会儿再试吧！"
                });
            }
        }) : app.util.request({
            url: "entry/wxapp/saveattestation",
            cachetime: "0",
            data: {
                user_id: t.data.userInfo.id,
                name: o,
                zj_name: i,
                code: n,
                zm_img: s,
                bm_img: c,
                type: 2,
                id: l
            },
            success: function(e) {
                if (console.log(e), "error" != e.data) {
                    wx.showToast({
                        title: "提交成功"
                    }), setTimeout(function() {
                        wx.navigateBack({
                            delta: 2
                        });
                    }, 1500);
                    var t = wx.getStorageSync("userInfo").openid;
                    app.util.request({
                        url: "entry/wxapp/Message3",
                        cachetime: "0",
                        data: {
                            form_id: a,
                            openid: t,
                            rz_id: e.data
                        },
                        success: function(e) {
                            console.log("发送模板消息"), console.log(e);
                        }
                    });
                } else wx.showModal({
                    title: "",
                    content: "系统出差了，待会儿再试吧！"
                });
            }
        });
    },
    identity: function(e) {
        wx.navigateTo({
            url: "../mycenter/inform?status=3"
        });
    },
    icon: function(e) {
        var t = this.data.icon;
        1 == t ? this.setData({
            icon: !1
        }) : this.setData({
            icon: !0
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {}
});